<script>
export default {
	onLaunch: async function () {
		console.log('App Launch')
		
		uni.showLoading({
			title: '加载中...',
			mask: true
		})

		try {
			// 从本地存储初始化状态
			await this.initAppState()
			// 判断登录状态
			if (this.$store.getters.hasLogin) {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			} else {
				uni.reLaunch({
					url: '/pages/login/index'
				})
			}
		} catch (error) {
			console.error('App初始化失败:', error)
			uni.reLaunch({
				url: '/pages/login/index'
			})
		} finally {
			uni.hideLoading()
		}
	},

	methods: {
		// 初始化应用状态
		async initAppState() {
			// 从storage读取数据到store
			await this.$store.dispatch('user/initUserState')
		}
	},

	onShow: function () {
		console.log('App Show')
	},
	onHide: function () {
		console.log('App Hide')
	}
}
</script>

<style lang="scss">
/*每个页面公共css */
@import 'uview-ui/index.scss';
</style>
